package com.lagou.rpc;

import com.lagou.configBean.ZkClient;
import org.apache.curator.framework.CuratorFramework;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.data.Stat;

/**
 * @author ascetic
 * @version 1.0
 * @ClassName RegisterService
 * @Description TODO
 * @date 2020-07-03 17:57
 */
public class RegisterService {

    public static  void reg(String serverName,String ip,String port) throws Exception {

        CuratorFramework client = ZkClient.getZKClient();
        Stat stat = client.checkExists().forPath(serverName);
        if(null == stat)
            client.create().withMode(CreateMode.PERSISTENT).forPath(serverName);

        client.create().withMode(CreateMode.EPHEMERAL).forPath(serverName+"/"+ip + ":"+port);

    }

}